using System;
using System.Collections.Generic;
using System.Text;
using System.Configuration;
using System.Configuration.Provider;
using System.Collections.Specialized;

namespace AAM.DAL
{
    public class BizProviderConfigurationElement : ConfigurationElement
    {

        private ProviderBase provider = null;

        [ConfigurationProperty("name", IsRequired = true)]
        public string Name { get { return (string)this["name"]; } }

        [ConfigurationProperty("type", IsRequired = true)]
        public string Type { get { return (string)this["type"]; } }

        [ConfigurationProperty("connectionStringName", IsRequired = true)]
        public string ConnectionStringName { get { return (string)this["connectionStringName"]; } }

        public ProviderBase Provider
        {
            get
            {
                if (provider == null)
                {
                    Type type = System.Type.GetType(Type);
                    provider = (ProviderBase)Activator.CreateInstance(type);
                    NameValueCollection nvc = new NameValueCollection();
                    nvc.Add("connectionStringName", ConnectionStringName);
                    provider.Initialize(Name, nvc);
                }
                return provider;
            }
        }

    }
}
